<?php

namespace app\api\model;

use think\Model;

class Banner extends Base
{
    protected $table = 'banner';
    protected $autoWriteTimestamp = 'datetime';


    public function items()
    {
        return $this->hasMany('BannerItem', 'banner_id', 'id');
    }

    public   function getBannerById($id)
    {

        try{
            $banner = $this->with(['items', 'items.img'])
                ->find($id);

        }catch (\Exception $e){

            $banner = null;

        }
        return $banner;
    }


}